package cn.chint.manage.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.chint.bo.NoticeTemp;
import cn.chint.manage.dao.NoticeUserDao;
import cn.chint.manage.service.NoticeUserService;

@Controller
public class NoticeUserController {

	@Autowired
	NoticeUserDao noticeUserDao;
	@Autowired
	NoticeUserService noticeUserService;
	@RequestMapping(value = "noUpd", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public String update(HttpServletRequest request){
		com.alibaba.fastjson.JSONObject o = new com.alibaba.fastjson.JSONObject();
		String openid = request.getParameter("openid");
		long id = 1;
		noticeUserService.update(openid,id);
		o.put("status", "1");
		return o.toJSONString();
	}
	
	@RequestMapping(value = "noUpd2", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public String noUpd2(HttpServletRequest request){
		com.alibaba.fastjson.JSONObject o = new com.alibaba.fastjson.JSONObject();
		String openid = request.getParameter("openid");
		long id = 2;
		noticeUserService.update(openid,id);
		o.put("status", "1");
		return o.toJSONString();
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "selUpd", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody 
	public Map select(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response){	
		
		List<NoticeTemp> ls = noticeUserService.select();
	    
		
		Map<String, Object> r = new HashMap<String, Object>();
		r.put("code", 0);
		r.put("msg", "");
		r.put("count", ls.size());
		r.put("data", ls);
		return r;
	}
}